import Vue from 'vue'
import App from './App.vue'
import {
  router
} from './router'

//引入store
import store from './store'

import {
  Select as select,
  Icon as icon,
  TreeSelect 
} from 'ant-design-vue';
Vue.use(select)
Vue.use(icon)
Vue.use(TreeSelect)


import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
Vue.use(VXETable)

//按需引入elementui组件
import {
  Row,
  Col,
  Menu,
  Submenu,
  MenuItem,
  MenuItemGroup,
  Breadcrumb,
  BreadcrumbItem,
  Popover,
  Button,
  Link,
  Tooltip,
  Checkbox,
  Radio,
  RadioGroup,
  RadioButton,
  Progress,
  Table,
  TableColumn,
  Empty,
  Dialog,
  Pagination,
  Loading,
  Image,
  Form,
  FormItem,
  Input,
  TabPane,
  Tabs,
  Select,
  Option,
  CheckboxGroup,
  Drawer,
  InputNumber,
  DatePicker,
  Autocomplete,
  Step,
  Steps,
  Tree,
  Upload,
  Cascader,
  Popconfirm,
  Dropdown,
  DropdownMenu,
  DropdownItem,
  MessageBox,
  Carousel,
  CarouselItem,
  Result,
  ColorPicker
} from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
import {
  message
} from '@/utils/resetMessage.js'
import '../theme/index.css' //引入自定义主题样式
Vue.use(Row);
Vue.use(Col);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Popover);
Vue.use(Button);
Vue.use(Link);
Vue.use(Tooltip);
Vue.use(Checkbox);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(RadioButton);
Vue.use(Progress);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Empty);
Vue.use(Dialog);
Vue.use(Pagination);
Vue.use(Loading);
Vue.use(Image);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);
Vue.use(TabPane);
Vue.use(Tabs);
Vue.use(Select);
Vue.use(Option);
Vue.use(CheckboxGroup);
Vue.use(Drawer);
Vue.use(InputNumber);
Vue.use(DatePicker);
Vue.use(Autocomplete);
Vue.use(Step);
Vue.use(Steps);
Vue.use(Tree);
Vue.use(Upload);
Vue.use(Cascader);
Vue.use(Popconfirm);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Carousel)
Vue.use(CarouselItem)
Vue.use(Result)
Vue.use(ColorPicker)

Vue.component(MessageBox)
Vue.prototype.$confirm = MessageBox.confirm;

Vue.prototype.$message = message;

//引入全局变量
import global from '@/global'
Vue.prototype.$global = global

//引入vue-json-viewer
import JsonViewer from "vue-json-viewer";
Vue.use(JsonViewer);

//web按钮权限
import webDirective from '@/utils/webDirective'

//引入自定义工具类函数
import myutil from "@/utils/myutils.js"
import enumCon from "@/utils/enumContast.js"
Vue.prototype.utils = myutil
Vue.prototype.enumCon = enumCon
Date.prototype.dateFormat = myutil.dateFormat;

//自定义样式
import './style/index.less';

//引入iconfont-SVG
import './assets/fonts/iconfont.js'

//引入矢量图标
import './assets/fonts/iconfont/iconfont.css';

//自动化注册全局组件
import './utils/registered.js'

//引入滚动插件
import scroll from 'vue-seamless-scroll';
Vue.use(scroll)

import Print from 'vue-print-nb'
Vue.use(Print)

//注册全局el-button失焦自定义指令
// Vue.directive('blur', {
//   // 当被绑定的元素插入到 DOM 中时……
//   inserted: function (el) {
//     function clickHandler(e) {
//       // 这里判断点击的元素是否是本身，是本身，则返回
//       if (el.contains(e.target)) {
//         // function blurFn(el){
//         //   let target = el.target
//         //   if (target.nodeName == "I" || target.nodeName == "SPAN") target = el.target.parentNode
//         //   target.blur()
//         // }
//         document.addEventListener('click', el => {
//           let target = el.target
//           if (target.nodeName == "I" || target.nodeName == "SPAN") target = el.target.parentNode
//           target.blur()
//         })
//         // el._blurFn_ = blurFn
//         console.log('come')
//       }else{
//         console.log('cancel')
//         // document.removeEventListener("click", el._blurFn_)
//       }
//     }
//     document.addEventListener("click", clickHandler)
//   }
// })
//注册全局函数节流自定义指令
Vue.directive('throttle', {
  inserted: (el, binding) => {
    let delay = binding.arg
    if (!delay) delay = 200
    let time = null
    el.addEventListener('click', () => {
      if (!time) {
        time = setTimeout(() => {
          binding.value()
          time = null
        }, delay)
      }
    })
  }
})

/**
 * 注册权限验证
 */
Vue.directive('hasPermis', {
  // 当被绑定的元素插入到 DOM 中时……
  inserted: function (el, binding) {
    if (binding.value == null) {
      return
    }
    webDirective(el, binding.value)
  }
})

//设置全局过滤器
import * as filters from './filters'
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false


const _this = new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')

export default _this